Skip to content

improve libc time and MSVC simulator#5775

Merged
Guozhanxin merged 9 commits into
RT-Thread:masterfrom
mysterywolf:libc
Apr 7, 2022
Merged

improve libc time and MSVC simulator#5775
Guozhanxin merged 9 commits into
RT-Thread:masterfrom
mysterywolf:libc

Conversation

@mysterywolf

@mysterywolf mysterywolf commented Apr 5, 2022

Copy link
Copy Markdown
Member

拉取/合并请求描述:(PR description)

  • [libc] 解决由于类unix操作系统发展历史原因fcntl.h定义的标志位在不同编译器中定义不同的问题
  • [simulator] 部分宏定义转为全局宏定义以确保vs内置文件可以正确配置
  • [simulator] 取消自欺欺人式的警告消除处理方式
  • [libc][time] 优化time相关结构体在不同编译器下的包含

以下的内容不应该在提交PR时的message修改,修改下述message,PR会被直接关闭。请在提交PR后,浏览器查看PR并对以下检查项逐项check,没问题后逐条在页面上打钩。
The following content must not be changed in the submitted PR message. Otherwise, the PR will be closed immediately. After submitted PR, please use a web browser to visit PR, and check items one by one, and ticked them if no problem.

当前拉取/合并请求的状态 Intent for your PR

必须选择一项 Choose one (Mandatory):

  • 本拉取/合并请求是一个草稿版本 This PR is for a code-review and is intended to get feedback
  • 本拉取/合并请求是一个成熟版本 This PR is mature, and ready to be integrated into the repo

代码质量 Code Quality:

我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:

  • 已经仔细查看过代码改动的对比 Already check the difference between PR and old code
  • 代码风格正确,包括缩进空格,命名及其他风格 Style guide is adhered to, including spacing, naming and other styles
  • 没有垃圾代码,代码尽量精简,不包含#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up
  • 所有变更均有原因及合理的,并且不会影响到其他软件组件代码或BSP All modifications are justified and not affect other components or BSP
  • 对难懂代码均提供对应的注释 I've commented appropriately where code is tricky
  • 本拉取/合并请求代码是高质量的 Code in this PR is of high quality
  • 本拉取/合并使用formatting等源码格式化工具确保格式符合RT-Thread代码规范 This PR complies with RT-Thread code specification

@mysterywolf mysterywolf requested a review from enkiller April 5, 2022 07:09
@mysterywolf mysterywolf changed the title [libc] 解决由于历史原因fcntl.h定义的值在不同编译器中定义不同的问题 [libc] 解决由于历史原因fcntl.h定义的值在不同编译器中定义不同的问题 | improve libc Apr 5, 2022
@mysterywolf mysterywolf changed the title [libc] 解决由于历史原因fcntl.h定义的值在不同编译器中定义不同的问题 | improve libc [libc][simulator] 解决由于历史原因fcntl.h定义的值在不同编译器中定义不同的问题 | improve libc Apr 5, 2022
@mysterywolf mysterywolf closed this Apr 5, 2022
@mysterywolf mysterywolf reopened this Apr 5, 2022
@mysterywolf mysterywolf changed the title [libc][simulator] 解决由于历史原因fcntl.h定义的值在不同编译器中定义不同的问题 | improve libc improve libc time and simulator Apr 5, 2022
@mysterywolf mysterywolf changed the title improve libc time and simulator improve libc time and MSVC simulator Apr 5, 2022
@mysterywolf mysterywolf requested a review from Guozhanxin April 5, 2022 17:36
Comment thread components/libc/compilers/common/sys/time.h
Comment thread bsp/simulator/rtconfig_project.h
Comment thread components/libc/compilers/common/sys/time.h Outdated
@mysterywolf

Copy link
Copy Markdown
Member Author

squash的时候帮我整理一下commit 复制下面的内容即可

- [libc] 解决由于类unix操作系统发展历史原因fcntl.h定义的标志位在不同编译器中定义不同的问题
- [simulator] 部分宏定义转为全局宏定义以确保vs内置文件可以正确配置
- [simulator] 取消自欺欺人式的警告消除处理方式
- [libc][time] 优化time相关结构体在不同编译器下的包含

@Guozhanxin Guozhanxin added the +1 Agree +1 label Apr 6, 2022
#include <winsock.h> /* for struct timeval */
#endif
#include <corecrt.h> /* for __time64_t */
typedef __time64_t time_t;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个地方要留意

get_timeval 和 set_timeval 里面有这样一段代码

static int set_timeval(struct timeval *tv)
{
    rst = rt_device_control(device, RT_DEVICE_CTRL_RTC_SET_TIME, &tv->tv_sec);
    rt_device_control(device, RT_DEVICE_CTRL_RTC_SET_TIMEVAL, tv);
}

vs 上 struct timeval 中的 tv_sec 类型是 long,RTC 驱动那边,会当成 time_t * 进行赋值,会造成不致命的内存越界

// 这种形式会写穿 tv_usec,不致命
struct timeval {
        long    tv_sec;         /* seconds */
        long    tv_usec;        /* and microseconds */
};

// 这种形式会写穿后面的内存,致命
struct timeval {
        long    tv_usec;        /* and microseconds */
        long    tv_sec;         /* seconds */
};

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

struct timeval {
        long    tv_usec;        /* and microseconds */
        long    tv_sec;         /* seconds */
};

这种倒过来的形式在newlib vs都没有 都是正着的
time64可以先放着,因为后续都要升级到64位了,要应对2038的问题。

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

看来2038的问题不只是time_t 32改64这么简单,相关的时间结构体 long都得改成longlong

@Guozhanxin Guozhanxin added the +2 Agree +2 label Apr 7, 2022
@Guozhanxin Guozhanxin merged commit c318dfa into RT-Thread:master Apr 7, 2022
@mysterywolf mysterywolf deleted the libc branch April 7, 2022 06:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

+1 Agree +1 +2 Agree +2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants